from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from ..config.config import config

print(config.DATABASE)
if config.DATABASE == "mysql":
    DATABASE_URL = f"mysql+pymysql://{config.USER}:{config.PASSWORD}@{config.HOST}:{config.PORT}/{config.SCHEMA}"
elif config.DATABASE == "postgresql":
    DATABASE_URL = f"postgresql://{config.USER}:{config.PASSWORD}@{config.HOST}:{config.PORT}/{config.SCHEMA}"
elif config.DATABASE == "sqlite":    # 使用sqlite
    DATABASE_URL = f"sqlite:///{config.SCHEMA}.db"

engine = create_engine(DATABASE_URL, echo=False)

sessionlocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
